package luanluan.control.buttons 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	/**
	 * 可以选中的按钮
	 * @author luanluan
	 * @version	1.0.1 2011.11.18
	 */
	public class LRadioButton extends LButton 
	{
		protected var _selected:Boolean = false;	//	是否被选中
		
		private var _group:LRadioGroup;
		
		/**
		 * 一个可以选中的按钮，即有选中状态和非选中状态
		 * @param	mc		一个具有三(四)帧的MovieClip(分别为非选中，鼠标经过，选中和不可点击状态)
		 * @param	hasGray	是否有不可点击状态(即第四帧),让用户知道这个按钮是不可以点击的
		 */
		public function LRadioButton(mc:MovieClip , hasGray:Boolean = false) 
		{
			super(mc, hasGray);
		}
		
		override protected function mouseClickHandle(e:MouseEvent):void 
		{
			super.mouseClickHandle(e);
			
			selected = !_selected;
			if (_group)
				_group.itemChangeHandle(this);
		}
		
		override protected function mouseOverHandle(e:MouseEvent):void 
		{
			mc.addEventListener(MouseEvent.ROLL_OUT, mouseOutHandle);
			mc.addEventListener(MouseEvent.CLICK, mouseClickHandle);
			mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandle);
		}
		
		override protected function mouseOutHandle(e:MouseEvent):void 
		{
			mc.removeEventListener(MouseEvent.ROLL_OUT, mouseOutHandle);
			mc.removeEventListener(MouseEvent.CLICK, mouseClickHandle);
			mc.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandle);
			if (_selected)
				mc.gotoAndStop(FLAG_DOWN);
			else
				mc.gotoAndStop(FLAG_UP);
		}
		
		public function get selected():Boolean 		{			return _selected;		}
		
		public function set selected(value:Boolean):void 
		{
			if (_selected == value || !_enabled)
				return;
				
			_selected = value;
			if (_selected)
			{
				mc.gotoAndStop(FLAG_DOWN);
			}
			else
			{
				mc.gotoAndStop(FLAG_UP);
			}
		}
		
		public function set group(value:LRadioGroup):void 
		{
			_group = value;
		}
		
	}

}